// 合成图片
import MC from 'mcanvas'
const SynthesisPhoto = ({ width, codeWidth, height, bg, codePos = {}, code, store_name, merchant_name, namePos = {}, fontSize = '30px' }) => {
    if (name.length > 15) {
        fontSize = `20px`
        namePos.y = namePos.y - 5
    }
    const mc = new MC({
        width,
        height,
        backgroundColor: '#fff'
    })
    return new Promise((resolve, reject) => {
        mc.background(bg, {
            left: 0,
            top: 0,
            color: '#000000',
            type: 'origin',
        })
            .add(code, {
                width: codeWidth,
                pos: codePos
            })
            .text(store_name, {
                width: '100%',
                align: 'center',
                pos: namePos,
                normalStyle: {
                    font: `${fontSize} Microsoft YaHei,sans-serif`,
                }
            })
            .draw({
                type: 'png',
                default: 1,
                quality: 1,
                success(base64) {
                    resolve({
                        merchant_name,
                        url: base64
                    })
                },
                error(err) {
                    reject(err)
                }
            })
    })
}
export { SynthesisPhoto }